import * as ccenv from 'cc/env'
import * as cc from 'cc'
import Rect from "../../libs/geom/Rect";
import { PokerConfig } from "../config/PokerConfig";
import { TextureConfig } from "../config/TextureConfig";
import { Intensify, PokerIntensify, Settle } from "./PokerIntensify";

const isDevelopment = ccenv.DEBUG;
const isProduction = !ccenv.DEBUG;

export default class Deck {

    static defaultDeck = new Deck('默认卡组');

    readonly uuid: string = 'D_' + TextureConfig.randomKey(5);
    constructor(
        public name: string = '',
        public pay: number = 0,
        public readonly pokers: PokerIntensify[] = PokerConfig.pokerArray.map(poker => {
            return new PokerIntensify(poker, [])
        })
    ) {
        if (isDevelopment) {
            //  基础分+200
            // for (const element of this.pokers) {
            //     if (element.poker === PokerConfig.H_9 || element.poker === PokerConfig.H_8 || element.poker === PokerConfig.H_7) {

            //     }
            //     element.intensify.push(new class extends Intensify {
            //         constructor() {
            //             super('基础分+200', { value: 200, settle: Settle.add })
            //         }
            //         onDraw(poker: cc.Node, widgetComp: cc.Widget): void {

            //         }
            //     })
            // }
        };
    }

    get size() {
        return this.pokers.length
    }

    getPokerIntensify(poker: PokerConfig.EnumPoker): PokerIntensify {
        for (const element of this.pokers) {
            if (element.poker === poker) {
                return element;
            }
        }
        throw 'getPokerIntensify error poker =' + poker
    }

    getPay() {
        return this.pay;
    }

    clone() {
        return new Deck(this.name, this.pay, this.pokers.map((v) => {
            return new PokerIntensify(v.poker, [...v.intensify]);
        }));
    }
}